/**
 * const EventEmitter = require('events').EventEmitter
 * 任何构造函数都可以继承 EventEmitter 的方法 on emit
 */
import EventEmitter from 'events'

class Dog extends EventEmitter {
  constructor(name) {
    super()
    this.name = name
  }
}

const simon = new Dog('simon')
simon.on('bark', function () {
  console.log(this.name, 'bared')
})

setInterval(() => {
  simon.emit('bark')
}, 1000)